<?php
namespace src;
use classlib\input;
use src\logic\Cadmin;
use classlib\core as C;
use classlib\core\controller;
class Csrsaction extends controller {
	public function main() {
		$view   = C\view::inst('extjs');
		Cadmin::chkaccess($view);
		$view->assign_by_ref('title', Cadmin::$name);
		$view->display('live/log/srsaction.ext.js');
	}

	public function dolist() {
		$view   = C\view::inst('json');
		Cadmin::chkaccess($view);
		list($start, $limit, $sort) = Cadmin::offset();
		$where  = array();
		$ip     = trim(input::post('ip'));
		if (!empty($ip)) {
			$where[] = array('ip', '%'.$ip.'%', \classlib\orm::OP_LIKE);
		}
		$stream  = trim(input::post('stream'));
		if (!empty($stream)) {
			$where[] = array('stream', '%'.$stream.'%', \classlib\orm::OP_LIKE);
		}
		$sdate  = input::post('sdate');
		if ($sdate) {
			$where[] = array('stime', strtotime($sdate), \classlib\orm::OP_GT);
		}
		$edate  = input::post('edate');
		if ($edate) {
			$where[] = array('stime', strtotime($edate), \classlib\orm::OP_LT);
		}
		$orm    = C\model::load('log.log.actions');
		$total  = $orm->get_total($where);
		$list   = array();
		if ($total) {
			$list = $orm->get_list($start, $limit, $where, '*', $sort);
			foreach ($list as &$item) {
				$item['stime']   = date('Y-m-d H:i:s', $item['stime']);
			}
		}
		$view->assign_by_ref('total', $total);
		$view->assign_by_ref('dataset', $list);
		$view->display();
	}
}